package leetcode.biweekly.week98;

//Solution1Test
public class Solution1 {

	public int minMaxDifference(int num) {
		char[] arr = String.valueOf(num).toCharArray();
		char c = '0', k = '0';
		for (int i = 0; i < arr.length; i++) {
			if (arr[i] != '9') {
				c = arr[i];
				break;
			}
		}
		char[] max = arr.clone();
		for (int i = 0; i < arr.length; i++) {
			if (max[i] == c) {
				max[i] = '9';
			}
		}
		char[] min = arr.clone();
		for (int i = 0; i < arr.length; i++) {
			if (min[i] == arr[0]) {
				min[i] = '0';
			}
		}
		int m = Integer.valueOf(new String(max));
		int l = Integer.valueOf(new String(min));
		return m - l;
	}
}
